package com.joeyee.echartsgenerator.echarts.wordcloud;

import com.github.abel533.echarts.json.GsonOption;
import com.github.abel533.echarts.style.itemstyle.Normal;
import com.joeyee.echartsgenerator.echarts.EnhancedOption;

public class EchartWordCloud {

    private static Normal createRandomItemStyle() {
        Normal normal = new Normal();
        normal.color("rgb(" + Math.round(Math.random() * 160) + ","
                + Math.round(Math.random() * 160) + ","
                + Math.round(Math.random() * 160) + ")");
        return normal;
    }

    public static GsonOption createWordCloud(WordCloudData wordCloudData){
        EnhancedOption option = new EnhancedOption();
        option.title().text(wordCloudData.getTitle());

        WordCloud wordCloud = new WordCloud(wordCloudData.getTitle());
//        wordCloud.type(SeriesType.wordCloud);
//        wordCloud.gridSize(2);
//        wordCloud.sizeRange(new Integer[]{20, 100});
//        wordCloud.rotationRange(new Integer[]{0, 0});
//        wordCloud.shape("triangle");

        /**
         * @description:
         * 这里有个比较坑的地方，原来的写法：wordCloud.size("80%", "80%")，但是这样死活都无法请求到，</br>
         * 后来尝试着改成wordCloud.size("800", "400");这样就没问题了，有可能个%号有关。
         * @author Joe Yee
         * @date: 2021/8/12 19:01
         */
//        wordCloud.size(wordCloudData.getSize());
//        wordCloud.textRotation(0, 0, 0, 0);
//        wordCloud.textPadding(0);
//        wordCloud.autoSize().enable(true).minSize(20);
//        wordCloud.data(new com.github.abel533.echarts.data.WordCloudData("Sam S Club", 10000),
//                new com.github.abel533.echarts.data.WordCloudData("Macys", 6181),
//                new com.github.abel533.echarts.data.WordCloudData("Amy Schumer", 4386),
//                new com.github.abel533.echarts.data.WordCloudData("Jurassic World", 4055),
//                new com.github.abel533.echarts.data.WordCloudData("Charter Communications", 2467),
//                new com.github.abel533.echarts.data.WordCloudData("Chick Fil A", 2244),
//                new com.github.abel533.echarts.data.WordCloudData("Planet Fitness", 1898),
//                new com.github.abel533.echarts.data.WordCloudData("Pitch Perfect", 1484),
//                new com.github.abel533.echarts.data.WordCloudData("Express", 1112),
//                new com.github.abel533.echarts.data.WordCloudData("Home", 965));
        wordCloud.size("800", "400");
        wordCloud.textRotation(wordCloudData.getTextRotation());
        wordCloud.textPadding(wordCloudData.getTextPadding());
        wordCloud.autoSize().enable(true).minSize(wordCloudData.getMinSize());
        wordCloud.data(wordCloudData.getItems());
        option.series(wordCloud);
        return option;
    }
}
